from database import engine, SessionLocal
from models.notification import RefreshToken
from sqlalchemy import inspect

# 检查refresh_tokens表是否存在
inspector = inspect(engine)
if 'refresh_tokens' in inspector.get_table_names():
    print('refresh_tokens表存在')
    columns = inspector.get_columns('refresh_tokens')
    for col in columns:
        print(f'  - {col["name"]}: {col["type"]}')
else:
    print('refresh_tokens表不存在')

# 检查是否有token记录
db = SessionLocal()
try:
    count = db.query(RefreshToken).count()
    print(f'refresh_tokens记录数量: {count}')
    if count > 0:
        latest = db.query(RefreshToken).order_by(RefreshToken.created_at.desc()).first()
        print(f'最新token创建时间: {latest.created_at}')
        print(f'是否撤销: {latest.is_revoked}')
        print(f'过期时间: {latest.expires_at}')
except Exception as e:
    print(f'查询refresh_tokens失败: {e}')
finally:
    db.close()